<?php
class Welcome_Model extends CI_Model{
	public function show(){
		$book = $this->uri->segment(3);
		if($book == 'all'){
			$this->load->library('pagination');
			$config['base_url'] = site_url('welcome/index/all');
			$config['total_rows'] = $this->db
				->select('attendance.date')
				->join('book','book.id = attendance.book_id','left')
				->where('book.incharge_id',$_SESSION['id'])
				->group_by('attendance.date')
				->count_all_results('attendance');
			$config['per_page'] = 10;
			$config['uri_segment'] = 4;
			$config['first_link'] = '首页';
			$config['last_link'] = '尾页';
			$config['prev_link'] = '上一页';
			$config['next_link'] = '下一页';
			$config['attributes'] = array('class' => 'myclass');
			$this->pagination->initialize($config);
			$query = $this->db
				->select('attendance.book_id,attendance.date ,sum(attendance.attendance_days) as duration,sum(attendance.attendance_salary) as price')
				->join('book','book.id = attendance.book_id','left')
				->where('book.incharge_id',$_SESSION['id'])
				->where('deleted',0)
				->order_by('attendance.date','DESC')
				->group_by('date')
				->get('attendance',$config['per_page'],$this->uri->segment(4));
			$data['info'] = $query->result();
			$data['page'] = $this->pagination->create_links();
			return $data;
		}else{
			$this->load->library('pagination');
			$config['base_url'] = site_url('welcome/index/'.$book);
			$config['total_rows'] = $this->db
				->select('attendance.date')
				->join('book','book.id = attendance.book_id','left')
				->where('book.incharge_id',$_SESSION['id'])
				->where('book.id',$book)
				->group_by('attendance.date')
				->count_all_results('attendance');
			$config['per_page'] = 10;
			$config['uri_segment'] = 4;
			$config['first_link'] = '首页';
			$config['last_link'] = '尾页';
			$config['prev_link'] = '上一页';
			$config['next_link'] = '下一页';
			$config['attributes'] = array('class' => 'myclass');
			$this->pagination->initialize($config);
			$query = $this->db
				->select('attendance.book_id,attendance.date ,sum(attendance.attendance_days) as duration,sum(attendance.attendance_salary) as price')
				->join('book','book.id = attendance.book_id','left')
				->where('book.incharge_id',$_SESSION['id'])
				->where('deleted',0)
				->order_by('attendance.date','DESC')
				->group_by('date')
				->get('attendance',$config['per_page'],$this->uri->segment(4));
			$data['info'] = $query->result();
			$data['page'] = $this->pagination->create_links();
			return $data;
		}
			
	}
}